<template>
  <div class="home-container">
    <van-image width="100vw" height="100vh" fit="cover" :src="require('../../assets/login_bg.png')" />
    <span class="home-title" :style="{ position: 'absolute', left: 0, right: 0, top: getStatusBarHeight }">
      潍坊市矿产资源管理系统
    </span>
    <div class="home-box">
      <div class="box-line-one">
        <div class="home-box-item box-kzgl" @click="handleClick('KZGL')">
          <van-image width="32px" height="32px" fit="contain" :src="require('../../assets/ic_kzgl.png')" />
          <span class="box-item-text">矿政管理</span>
        </div>
        <div class="home-box-item box-jksb" @click="handleClick('JKSB')">
          <van-image width="32px" height="32px" fit="contain" :src="require('../../assets/ic_jksb.png')" />
          <span class="box-item-text">监控设备</span>
        </div>
      </div>

      <div class="box-line-two">
        <div class="home-box-item box-jkyj" @click="handleClick('JKYJ')">
          <van-image width="32px" height="32px" fit="contain" :src="require('../../assets/ic_jkyj.png')" />
          <span class="box-item-text">监控预警</span>
        </div>
        <div class="home-box-item box-grzx" @click="handleClick('GRZX')">
          <van-image width="32px" height="32px" fit="contain" :src="require('../../assets/ic_grzx.png')" />
          <span class="box-item-text">个人中心</span>
        </div>
      </div>
    </div>
    <span class="home-unit">潍坊市自然资源和规划局</span>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  components: {},
  data() {
    return {
      statusBarHeight: 24
    }
  },
  computed: {
    ...mapGetters(['getNativeCallJs', 'getNativeApi']),
    getStatusBarHeight() {
      return this.statusBarHeight + 'px'
    }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      vm.getNativeCallJs.registerNativieGoBack(() => {
        vm.goBack()
      })
    })
  },
  created() {
    this.getNativeApi.setStatusBarColor('#00FFFFFF')
    this.getNativeApi.setStatusBarLightMode(false)
    this.getNativeApi.getStatusBarHeight().then(result => {
      this.statusBarHeight = result.data
    })
  },
  methods: {
    goBack() {
      this.$toast({
        message: '再次滑动退出app'
      })
      if (!this.first) {
        this.first = Date.now()
        setTimeout(() => {
          this.first = 0
        }, 1000)
      } else {
        if (Date.now() - this.first < 1000) {
          this.getNativeApi.closeApp()
          console.log('退出登录')
          this.first = 0
        }
      }
    },
    handleClick(tag) {
      switch (tag) {
        case 'KZGL':
          this.$router.push('/kzgl')
          break
        case 'JKSB':
          this.$router.push('/jksb')
          break
        case 'JKYJ':
          this.$toast('功能正在开发中...')
          // this.$router.push('/jkyj')
          break
        case 'GRZX':
          this.$router.push('/grzx')
          break
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.home-container {
  width: 100vw;
  height: 100vh;
  position: relative;
}
.home-title {
  height: 44px;
  font-weight: 800;
  font-size: 18px;
  color: #ffffff;
  line-height: 44px;
  text-align: center;
}
.home-box {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 21vh;
  .box-line-one {
    display: flex;
  }
  .box-line-two {
    display: flex;
    margin-top: 12px;
  }
  .home-box-item {
    width: calc(50vw - 6px);
    height: 14.8vh;
    border-radius: 8px;
    opacity: 0.9;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .box-kzgl {
    background: linear-gradient(137deg, #01b7fe 0%, #08aeef 36%, #007dfe 100%);
    box-shadow: 0px 0 20px 0px rgba(0, 71, 142, 0.5);
  }
  .box-jksb {
    background: linear-gradient(135deg, #28de5f 0%, #26cfe7 100%);
    box-shadow: 0px 0 20px 0px rgba(0, 76, 35, 0.5);
    margin-left: 12px;
  }
  .box-jkyj {
    background: linear-gradient(134deg, #ffbb48 0%, #ff7e00 100%);
    box-shadow: 0px 0 20px 0px rgba(157, 79, 0, 0.5);
  }
  .box-grzx {
    background: linear-gradient(134deg, #878ffc 0%, #4882f0 100%);
    box-shadow: 0px 0 20px 0px rgba(0, 37, 105, 0.5);
    margin-left: 12px;
  }
  .box-item-text {
    font-size: 16px;
    color: #ffffff;
  }
}
.home-unit {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8.6vh;
  font-size: 15px;
  color: #ffffff;
  text-align: center;
}
</style>
